package com.ccys.cms.controller.marketing;

import com.ccys.cms.service.marketing.NewsWebService;
import com.ccys.common.constants.ContextConstants;
import com.ccys.common.constants.TouristApi;
import com.ccys.common.util.Kit;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.CommonDto;
import com.ccys.db.dto.marketing.NewsDTO;
import com.ccys.db.entity.TblNews;
import com.ccys.db.vo.administrator.ClinicSelectListWebVO;
import com.ccys.db.vo.marketing.AnalysisFileBenifitDataWebVO;
import com.ccys.db.vo.marketing.NewsDetailWebVO;
import com.ccys.db.vo.marketing.NewsWebVO;
import com.ccys.db.vo.marketing.PlanSelectListWebVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "市场设置-news")
@RequestMapping("marketing")
public class NewsWebController {

    @Autowired
    private NewsWebService newsWebService;

    @GetMapping("news")
    @ApiOperation("获取列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "title", value = "title", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "countryIds", value = "国家ID", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "status", required = false, dataType = "string", paramType = "query"),


        @ApiImplicitParam(name = "id", value = "对象id", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startTime", value = "开始时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "endTime", value = "结束时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "orderByStr", value = "排序字段（后端返回的字段  asc升序，desc 降序,加上end后缀。示例（createdOn降序排 则传值 createdOn descend））",paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = NewsWebVO.class)
    })
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, @ApiIgnore NewsDTO dto) {
        return this.newsWebService.listObjectsCms(request, response, dto);
    }

    @GetMapping("news/plan")
    @ApiOperation("查询选择配套Plan")
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = PlanSelectListWebVO.class)
    })
    public ResponseResult listPlanSelectListWebVO(HttpServletRequest request, HttpServletResponse response, @ApiIgnore NewsDTO dto) {
        return this.newsWebService.listPlanSelectListWebVO(request, response, dto);
    }

    @GetMapping("news/detail")
    @ApiOperation("查询详情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "对象id", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = NewsDetailWebVO.class)
    })
    public ResponseResult getDetail(HttpServletRequest request, HttpServletResponse response, @ApiIgnore NewsDTO dto) {
        return this.newsWebService.getDetail(request, response, dto);
    }



    //通过文件地址解析出文件中的 Policy Number 再根据 Policy Number 找到 benifit相关数据
    @TouristApi
    @PostMapping("analysisFileBenifitData")
    @ApiOperation("上传文件（multipart/form-data 方式）解析文件中关联的benifit数据")
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = AnalysisFileBenifitDataWebVO.class)
    })
    public ResponseResult analysisFileBenifitData(HttpServletRequest request,
                                                  @ApiParam(value = "上传的文件", required = true)
                                                  @RequestParam(value = "file", required = true)@RequestBody MultipartFile file, @ApiIgnore NewsDTO dto) {
        return this.newsWebService.analysisFileBenifitData(request,dto,file);
    }

    @PostMapping("news")
    @ApiOperation("添加")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "fileUploadPath", value = "直接传文件解析后的逗号拼接的数据", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "planBenefitIds", value = "File upload 类型时 用户选择的BenefitId (发送新闻用,不记录)", required = false, dataType = "string", paramType = "query"),

        @ApiImplicitParam(name = "title", value = "title", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "countryIds", value = "0 全部;多个国家 id 以英文逗号拼接，老数据存在|拼接的情况", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "status", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startDate", value = "startDate", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pinned", value = "pinned", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "showHomepage", value = "showHomepage", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "showFutureUser", value = "showFutureUser", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "image", value = "image", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "description", value = "Short description", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "content", value = "content", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "targetType", value = "1	AIA corporate;2	direct corporate;3	AIA HealthShield;4	Subscription Package;5	Ltria Corporate;6	AIA Absolute Critical Cover", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "targetPolicies", value = "targetPolicies（选择的planID）", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "jobId", value = "jobId", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsRouteUsers", value = "0	Subscription;1	General Practitioner;2	Mental Wellness;3	Paediatrician;4:URL ;8:ThinkWell", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "totalSent", value = "totalSent", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "currentSent", value = "currentSent", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsIsShowContent", value = "是否Call to action", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsSelectBy", value = "targetType 为AIA corporate 时,1:list;2:file upload", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsSelectBencode", value = "存储 targetType 为AIA corporate 是上传文件解析后选中的benched", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "ctaDestination", value = "1:content 2:URL", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "showProceed", value = "showProceed", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsUrl", value = "newsUrl", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult save(@ApiIgnore NewsDTO entity) {
        entity.setId(null);
        return this.newsWebService.change(entity);
    }


    @PutMapping("news")
    @ApiOperation("编辑")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "fileUploadPath", value = "直接传文件解析后的逗号拼接的数据", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "planBenefitIds", value = "File upload 类型时 用户选择的BenefitId (发送新闻用,不记录)", required = false, dataType = "string", paramType = "query"),

        @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "title", value = "title", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "countryIds", value = "0 全部;多个国家 id 以英文逗号拼接，老数据存在|拼接的情况", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "status", value = "status", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startDate", value = "startDate", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pinned", value = "pinned", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "showHomepage", value = "showHomepage", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "showFutureUser", value = "showFutureUser", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "image", value = "image", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "description", value = "Short description", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "content", value = "content", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "targetType", value = "1	AIA corporate;2	direct corporate;3	AIA HealthShield;4	Subscription Package;5	Ltria Corporate;6	AIA Absolute Critical Cover", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "targetPolicies", value = "targetPolicies（选择的planID）", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "jobId", value = "jobId", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsRouteUsers", value = "0	Subscription;1	General Practitioner;2	Mental Wellness;3	Paediatrician;4:URL ;8:ThinkWell", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "totalSent", value = "totalSent", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "currentSent", value = "currentSent", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsIsShowContent", value = "是否Call to action", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsSelectBy", value = "targetType 为AIA corporate 时,1:list;2:file upload", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsSelectBencode", value = "存储 targetType 为AIA corporate 是上传文件解析后选中的benched", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "ctaDestination", value = "1:content 2:URL", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "showProceed", value = "showProceed", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "newsUrl", value = "newsUrl", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult edit(@ApiIgnore NewsDTO entity) {
        Kit.allParamValid(entity, "id");
        return this.newsWebService.change(entity);
    }


    @DeleteMapping("news")
    @ApiOperation("删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query")
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult delete(TblNews dto) {
        Kit.allParamValid(dto, "id");
        return this.newsWebService.delete(dto);
    }

}